<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SBCD Instruction</title>
<link href="../edit68k.css" rel="stylesheet" type="text/css">
</head>

<body>
<h1 class="heading">SBCD Instruction<BR>
</h1>
<hr noshade></h1>
        <BR>
          <span class="text">The instruction SBCD (Subtract BCD with extend) subtracts two bytes in BCD-form. The difference (destination - source - X flag) is stored in the destination register.<BR>
          <BR>
  ADDRESS METHODS: Dn, -(An)<BR>
          <BR>
  There are two ways to use this instruction:<BR>
          <BR>
  1. Subtract a data register from a data register (address method Dn). The lower byte in the source register is subtracted from the lower byte in the destination register, where the answer is stored.<BR>
          <BR>
  2. Subtract memory from memory. This way, you can subtract big numbers stored in many bytes. Since you only can use -(An) you must start on the highest byte (the least significant digits in the BCD number) and work down. If there is a carry, the X bit is set, which will be subtracted from the next byte.<BR>
          <BR>
  DATA LENGTH: Byte</span></P>
        <TABLE border=0 cellPadding=0 cellSpacing=0 width="68%">
          <TBODY>
            <TR>
              <TD width="13%" rowSpan=5 vAlign=top class="text">FLAGS: </TD>
              <TD width="87%" class="text">X - Set if a loan was required when subtracting, else cleared</TD>
            </TR>
            <TR>
              <TD width="87%" class="text">N - undef</TD>
            </TR>
            <TR>
              <TD width="87%" class="text">Z - Cleared if the result was 0, else unaffected</TD>
            </TR>
            <TR>
              <TD width="87%" class="text">C - Same as X</TD>
            </TR>
            <TR>
              <TD width="87%" class="text">V - undef</TD>
            </TR>
          </TBODY>
        </TABLE>
        <P align=left class="text">The Z flag is cleared if the result is not 0. This way, you can see if the answer, after a series of subtractions, is zero or not. First, you have to set the Z flag (done by comparing a register with itself). Then do the subtraction, and if the Z flag is set, the BCD number is zero.</P>
        <TABLE border=0 cellPadding=0 cellSpacing=0 width="68%">
          <TBODY>
            <TR>
              <TD width="24%" rowSpan=2 class="text">SYNTAX:</TD>
              <TD width="76%" class="text">SBCD Dx,Dy</TD>
            </TR>
            <TR>
              <TD width="76%" class="text">SBCD -(Ax),-(Ay)</TD>
            </TR>
          </TBODY>
        </TABLE>
        <span class="text">
        </span><span class="text">
  </span>
<P align=left><span class="text"><strong style="font-weight: 400">EXAMPLE CODE:</strong></span></P>
<P align=left class="sourcecode"><strong style="font-weight: 400">
<font face="Arial" size="2">&nbsp;&nbsp; SBCD.B&nbsp;&nbsp;&nbsp; D0,D1&nbsp;&nbsp;&nbsp; 
 
Subtracts the 2 BCD numbers in D0 and D1 and stores the answer in D1</font></strong></P>
</body>
</html>